using System.Xml;

namespace RunCamlSample.QueryBuilders
{
    /// <summary>
    /// Create By: Nguyen Thanh Tung
    /// </summary>
    public abstract class BaseQueryBuilder
    {
        public XmlNode AddXmlElement(XmlNode parent, string elementName, string elementValue)
        {
            XmlNode element = parent.AppendChild(parent.OwnerDocument.CreateNode(XmlNodeType.Element, elementName, ""));

            if (elementValue != "")

                element.InnerText = elementValue;

            return (element);
        }

        public XmlNode AddXmlElement(XmlDocument parent, string elementName, string elementValue)
        {
            XmlNode element = parent.AppendChild(parent.CreateNode(XmlNodeType.Element, elementName, ""));

            if (elementValue != "")

                element.InnerText = elementValue;

            return (element);
        }

        public XmlNode AddXmlAttribute(XmlNode element, string attrName, string attrValue)
        {
            XmlNode attr = element.Attributes.Append((XmlAttribute)element.OwnerDocument.CreateNode(XmlNodeType.Attribute, attrName, ""));

            if (attrValue != "")

                attr.Value = attrValue;

            return (attr);
        }
    }
}